package com.lwc.service.impl;

import com.lwc.bean.TaoCan;
import com.lwc.mapper.TaoCanMapper;
import com.lwc.service.TaoCanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TaoCanServiceImpl implements TaoCanService {
    @Autowired
    TaoCanMapper taoCanMapper;

    @Transactional
    @Override
    public int save(List<TaoCan> taoCanList) {
//删除不在集合的套餐
taoCanMapper.batchDelete(taoCanList);
        //遍历集合 筛选出有id的
        taoCanList.forEach(e->{
            //判断是否是旧数据
            if (e.getId()>0){
                //更新
                taoCanMapper.update(e);
            }else {
                //新增
taoCanMapper.save(e);
            }

        });
        return 1;
    }


    @Override
    public List<TaoCan> query() {
        return taoCanMapper.query();
    }


}
